/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonysite.sessionbean;

import com.matrimonysite.entity.Users;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author khanhnguyen
 */
@Stateless
public class UsersFacade extends AbstractFacade<Users> {

    @PersistenceContext(unitName = "MatrimonySite-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    @Override
    public void create(Users user) {
        em.persist(user);
    }

    @Override
    public void edit(Users user) {
        em.merge(user);
    }

    @Override
    public void remove(Users user) {
        em.remove(em.merge(user));
    }

    public UsersFacade() {
        super(Users.class);
    }
    public Users getUserID(String userID) {
        Users user = null;
        try {
            Query query = em.createNamedQuery("Users.findByUserID");
            query.setParameter("userID", userID);
            user = (Users) query.getSingleResult();
        } catch (NoResultException ex) {
            ex.printStackTrace();
        }
        return user;
    }
    public Users getUserName(String username) {
        Users user = null;
        try {
            Query query = em.createNamedQuery("Users.findByUsername");
            query.setParameter("username", username);
            user = (Users) query.getSingleResult();
        } catch (NoResultException ex) {
            ex.printStackTrace();
        }
        return user;
    }

    public Users getPassWord(String password) {
        Users user = null;
        try {
            Query query = em.createNamedQuery("Users.findByPassword");
            query.setParameter("password", password);
            user = (Users) query.getSingleResult();
        } catch (NoResultException ex) {
            ex.printStackTrace();
        }
        return user;
    }

    public Users getEmail(String email) {
        Users user = null;
        try {
            Query query = em.createNamedQuery("Users.findByEmail");
            query.setParameter("email", email);
            user = (Users) query.getSingleResult();
        } catch (NoResultException ex) {
            ex.printStackTrace();
        }
        return user;
    }

    public Users getLastLogin(String lastlogin) {
        Users user = null;
        try {
            Query query = em.createNamedQuery("Users.findByLastLogin");
            query.setParameter("lastlogin", lastlogin);
            user = (Users) query.getSingleResult();
        } catch (NoResultException ex) {
            ex.printStackTrace();
        }
        return user;
    }

    public Users getUserStatus(String userstatus) {
        Users user = null;
        try {
            Query query = em.createNamedQuery("Users.findByUserStatus");
            query.setParameter("userstatus", userstatus);
            user = (Users) query.getSingleResult();
        } catch (NoResultException ex) {
            ex.printStackTrace();
        }
        return user;
    }

    public Users getCreatedDate(String createddate) {
        Users user = null;
        try {
            Query query = em.createNamedQuery("Users.findByCreatedDate");
            query.setParameter("createddate", createddate);
            user = (Users) query.getSingleResult();
        } catch (NoResultException ex) {
            ex.printStackTrace();
        }
        return user;
    }
}
